// $Id: server.h 110 2011-11-05 16:09:49Z cedric.shih@gmail.com $
/*
 * Copyright 2011 Cedric Shih (cedric dot shih at gmail dot com)
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

#ifndef NIORTSP_SERVER_H_
#define NIORTSP_SERVER_H_

#include <sys/queue.h>
#include <niortsp/transport.h>

struct event_base;

struct niortspd *niortspd_new(struct event_base *evbase);

void niortspd_free(struct niortspd *server);

int niortspd_bind(struct niortspd *server,
		const char *address, unsigned short port);

struct niortp_transport;

int niortspd_add_transport(struct niortspd *server,
		enum niortp_transport_type type, unsigned char payload_type,
		struct niortp_transport *transporter);

struct niortsp_media;

typedef int (*niortsp_media_describe_cb)(struct niortsp_media *media,
		u_int32_t session, const char *uri, struct zcbuffer *buffer,
		void *cbarg);

int niortspd_add_media(struct niortspd *server, const char *name,
		niortsp_media_describe_cb describe, void *cbarg);

int niortspd_remove_media(struct niortspd *server, const char *name);

struct niortsp_track;

typedef int (*niortsp_track_cb)(struct niortsp_track *track, void *cbarg);

typedef int (*niortsp_track_describe_cb)(struct niortsp_track *track,
		const char *uri, const char *name,
		struct zcbuffer *buffer, void *cbarg);

typedef void (*niortsp_track_finalize_cb)(
		struct niortsp_track *track, void *cbarg);

int niortspd_add_track(struct niortspd *server, const char *media_name,
		const char *name, unsigned char payload_type,
		niortsp_track_describe_cb describe,
		niortsp_track_cb setup, niortsp_track_cb teardown,
		niortsp_track_cb refresh, niortsp_track_finalize_cb finalize,
		void *cbarg);

int niortspd_remove_track(struct niortspd *server, struct niortsp_track *track);

int niortsp_track_push(struct niortsp_track *track, struct timeval *timestamp,
		struct zcbuffer *buffer);

struct niortsp_session_item {
	TAILQ_ENTRY(niortsp_session_item) next;
};

TAILQ_HEAD(niortsp_session_list, niortsp_session_item);

struct niortspd;

struct niortsp_session_list *niortsp_sessions(struct niortspd *server);

#endif /* NIORTSP_SERVER_H_ */
